<template>
	<view class="content">

		<Loading class="loading-box" style="position: fixed;" v-show="!isLoading" :isStatus='loadStatus'></Loading>
		<view class="">
			<cu-custom bgColor="bg-white" :isBack="true" textRight="true" type="custom-recuit">
				<block slot="backText" class="titilestyle">{{title}}</block>

			</cu-custom>
			<view class="" :style="[{marginTop:StatusBar.top+StatusBar.height+'px'}]">

			</view>

			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
				:down="downOption" :up="upOption" style="background-color: #0000FF;">
				<!-- 列表框 -->
				<view class="list-scroll" v-if="postData.length>0">

					<PostList @clickItem="jumpTo" :postData='postData'></PostList>
				</view>

			</mescroll-body>
		</view>

	</view>
</template>
<script>
	import PostList from "../../components/postList.vue"
	import MescrollBody from "@/uni_modules/mescroll-uni/components/mescroll-body/mescroll-body.vue"
	export default {
		components: {
			PostList,
			MescrollBody,
		},
		data() {
			return {
				title: "",
				isLoading: false, //是否加载完成显示
				loadStatus: 'load',
				resDomain: this.resDomain,
				StatusBar: this.Custom,
				postData: [],
				mescroll: null,
				downOption: {
					use: false, // 是否启用下拉刷新; 默认true
					native: false,
					auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
				},
				upOption: {
					use: true, // 是否启用上拉加载; 默认true
					auto: true, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					load: false,
					onScroll: true,
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据',
						tips: ""
					},
					textNoMore: '到底啦'
				},
				param: {
					area_id: uni.getStorageSync('area_id'),
					page: 0,
					limit: 10,
					type: "",
					school: "",
					keywords: "",
					city: "",
					status:0,

				},
				swiperHeight: "",
				type: "",
				interface: ""
			}

		},
		onLoad(option) {
			switch (option.type) {
				case "history":
					this.title = "浏览历史";
					this.interface = "/buyer/OfferHistory";


					break;
				case "collection":
					this.title = "我的收藏";
					this.interface = "/buyer/OfferCollectionList";
					break;
				case "all":
					this.title = "投递列表";
					this.param.status=option.status;
					this.interface = "/buyer/OfferOrderList";
					break;
			}


		},
		onReady() {
			this.getInfo().then((e) => {

				this.swiperHeight = e.screenHeight - (e.custom.top + e.custom.height * 2);

				this.isLoading = true;

			})
		},
		onPullDownRefresh() {
			this.downCallback();
		},
		onReachBottom() {
			this.upCallback(this.mescroll);
		},
		methods: {
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			downCallback() {
				console.log("下拉刷新");
				this.upCallback(this.mescroll);
			},
			upCallback(page) {
				console.log("加载数据");
				this.param.page = page.num;
				this.param.limit = page.size;
				this.apiRequest(this.interface, this.param, 0, "get").then(res => {
					if (page.num == 1) {
						this.postData = []
					}
					uni.stopPullDownRefresh();
					if (res.code != 200) {
						this.mescroll.endSuccess()
					} else {
						let arr = [];
						let dat="";
						(typeof res.data.total!="undefined")?(()=>{
							dat=res.data.data;
						})():(()=>{
							dat=res.data;
						})();
						dat.forEach((item) => {
							(item.offer) ? (() => {
								arr.push(item.offer);
							})() : "";
						})
						this.postData = this.postData.concat(arr); //追加新数据
						this.mescroll.endBySize(this.postData.length, res.data.total);
					}
				}).catch(() => {
					uni.stopPullDownRefresh()
					this.mescroll.endErr();
				})


			},


			jumpTo(...dat) {
				console.log(dat[0]);
				switch (dat[1]) {
					case "0":
						uni.navigateTo({
							url: "/app/Offer/pages/index/postCategory"
						})
						break;
					case "post":
						uni.navigateTo({
							url: "/app/Offer/pages/index/postInfo?offer_id=" + this.postData[dat[0]].offer_id
						})
						break;
					case "search":
						uni.navigateTo({
							url: "/app/Offer/pages/index/search"
						})

						break;
				}


			}




		}



	}
</script>

<style scoped>
	/**
	 * 搜索框样式
	 */
	.search-boxes {
		width: 92%;
		margin: auto;
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		align-items: center;
		box-shadow: 0px 0px 20upx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
		padding: 20upx 30upx 20upx 30upx;

	}

	.input-search-box1 {
		width: 100%;
		display: flex;
		align-items: center;
		position: relative;

	}

	.inputSearch1 {
		width: 80%;
	}

	/**
	 * banner样式
	 */
	.bannerBox {
		width: 92%;
		margin: 30upx auto;
		height: 200upx;
	}

	.lunboBox {
		width: 100%;
		height: 100%;
	}

	.swiper {
		width: 100%;
		height: 100%;
	}

	.screen-swiper {
		width: 100%;
		height: 100%;
	}

	.lunboImg {
		width: 100%;
		height: 100%;
		border-radius: 15rpx;
		position: relative;
	}

	/**
	 * 筛选框样式
	 */
	.screen-box {
		width: 92%;
		margin: 30upx auto 0 auto;
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		border-radius: 20upx;
		box-shadow: 0px 0px 20upx 0px rgba(0, 0, 0, 0.05);
	}

	.screen-tab {
		margin: auto;
		width: 30%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
	}

	/**
	 * tab
	 */
	.order-tap-select {
		font-size: 28upx;
		font-weight: 800;
		color: #333333;
	}

	.order-tab-no {
		font-size: 28upx;
		font-weight: 500;
		color: #999999;
	}

	.orderline {
		width: 30%;
		height: 6upx;
		background: #1270E0;
		border-radius: 30%;
		position: absolute;
		bottom: 10rpx;
	}

	.tag-style {
		max-width: 240rpx;
		height: 50rpx;
		line-height: 50rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: block;
	}

	/**
	 * 应用列表样式
	 */
	.appBox {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		margin-top: 40upx;
	}

	.app-item {
		display: flex;
		width: 20%;
		height: 120upx;
		margin-bottom: 20upx;
		flex-direction: column;
	}

	.app-icon {
		width: 100%;
		height: 90upx;
	}

	.app-img {
		width: 100%;
		height: 100%;
	}

	.app-name {
		width: 100%;
		text-align: center;
		height: 40upx;
		line-height: 40upx;
	}
</style>

<style lang="scss">
	.item-bottom {
		margin-left: 20rpx;
		width: 750*0.92-60-96rpx;
	}
</style>
